﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace NomCafe
{
    public partial class frmChangePassword : DevComponents.DotNetBar.Office2007RibbonForm
    {
        public string dbSchema = "[7nghe_com_nom]";

        public frmChangePassword()
        {
            InitializeComponent();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {            
            this.Close();
        }

        private void btnAccept_Click(object sender, EventArgs e)
        {   
            if (txtOldPassword.Text.Trim() != Lib_Cashier.password.Trim())
            {
                MessageBox.Show(languageCashier.CHANGE_PASS_ERROR, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtOldPassword.Focus();
            }
            else
            {
                if (txtNewPassword.Text == "" || txtRenewPassword.Text == "")
                {
                    MessageBox.Show(languageCashier.CHANGE_PASS_ERROR,"ERROR",MessageBoxButtons.OK,MessageBoxIcon.Error);
                }
                else
                {
                    string _strConn = "Data Source=112.213.85.26,2319;Network Library=DBMSSOCN;Initial Catalog=7nghe_db;User ID=7nghe_admin;Password=ava-jPlmpx5YV0;";
                    SqlConnection conn = new SqlConnection(_strConn);
                    try
                    {
                        conn.Open();
                        SqlCommand myCommand = new SqlCommand("UPDATE" + dbSchema + ".tblUser set password =N'" + txtNewPassword.Text.Trim() + "' WHERE username = N'" + Lib_Cashier.username + "'");
                        myCommand.Connection = conn;
                        myCommand.ExecuteNonQuery();
                        MessageBox.Show(languageCashier.CHANGE_PASS_SUCCE);
                        this.Close();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString());
                    }
                }
            }
        }

        private void btnRenew_Click(object sender, EventArgs e)
        {            
            txtNewPassword.Text = "";
            txtOldPassword.Text = "";
            txtRenewPassword.Text = "";
        }        
    }
}
